home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / banging_the_metal / qdos / qdos4amiga2 / romsrc / sys / movep_asm < prev    next >
Text File  |  2000-01-03  |  6KB  |  308 lines

  1. ; INPUT *************************************************************** #
  2. ;  none                                #
  3. ;                                #
  4. ; OUTPUT ************************************************************** #
  5. ;  If exiting through isp_dacc...                    #
  6. ;   a0 = failing address                        #
  7. ;   d0 = FSLW                            #
  8. ;  else                                #
  9. ;   none                             #
  10. ;                                #
  11. ; ALGORITHM *********************************************************** #
  12. ;  Decode the movep instruction words stored at EXC_OPWORD and     #
  13. ;  either read or write the required bytes from/to memory. Use the    #
  14. ;  _dmem_{read,write}_byte() routines. If one of the memory routines    #
  15. ;  returns a failing value, we must pass the failing address and a FSLW #
  16. ;  to the _isp_dacc() routine.                    #
  17. ;  Since this instruction is used to access peripherals, make sure    #
  18. ;  to only access the required bytes.                #
  19.  
  20. ; XDEF _moveperipheral    ; emulate movep instruction
  21.  
  22. ; XREF _dmem_read_byte    ; read byte from memory
  23. ; XREF _dmem_write_byte    ; write byte to memory
  24. ; XREF _isp_dacc        ; handle data access error exception
  25.  
  26. ; ###########################
  27. ; movep.(w,l)    Dx,(d,Ay) #
  28. ; movep.(w,l)    (d,Ay),Dx #
  29. ; ###########################
  30.  
  31. EXC_AREGS    equ    4+$20
  32. EXC_DREGS    equ    4+$0
  33. EXC_PC        equ    4+$42
  34.  
  35. EXC_OPWORD    equ    $0
  36. EXC_EXTWORD    equ    $2
  37.  
  38. _moveperipheral:
  39.  
  40.     move.l    EXC_PC(a7),a6
  41.     move.w    EXC_OPWORD(a6),d1     ; fetch the opcode word
  42.  
  43.     move.b    d1,d0
  44.     and.w    #$7,d0            ; extract Ay from opcode word
  45.  
  46.     dc.w    $2077,$0424        ; move.l   (EXC_AREGS,a7,d0.w*4),a0   ; fetch ay
  47. ;    lsl.w    #2,d0
  48. ;    move.l    EXC_AREGS(a7,d0.w),a0
  49. ;    lsr.w    #2,d0
  50.  
  51.     add.w    EXC_EXTWORD(a6),a0    ; add: an + sgn_ext(disp)
  52.  
  53.     btst    #$7,d1            ; (reg 2 mem) or (mem 2 reg)
  54.     beq.w    mem2reg
  55.  
  56. ; reg2mem: fetch dx, then write it to memory
  57. reg2mem:
  58.     move.w    d1,d0
  59.     rol.w    #$7,d0
  60.     and.w    #$7,d0            ; extract Dx from opcode word
  61.  
  62.     dc.w    $2037,$0404        ; move.l   (EXC_DREGS,a7,d0.w*4),d0   ; fetch dx
  63. ;    lsl.w    #2,d0
  64. ;    move.l    EXC_DREGS(a7,d0.w),d0
  65. ;    lsr.w    #2,d0
  66.  
  67.     btst    #$6,d1            ; word or long operation?
  68.     beq.b    r2mwtrans
  69.  
  70. ; a0 = dst addr
  71. ; d0 = Dx
  72. r2mltrans:
  73.     move.l    d0,d2            ; store data
  74.     move.l    a0,a2            ; store addr
  75.     rol.l    #$8,d2
  76.     move.l    d2,d0
  77.  
  78.     bsr.l    _dmem_write_byte        ; os  : write hi
  79.  
  80.     tst.l    d1            ; dfetch error?
  81.     bne.w    movp_write_err        ; yes
  82.  
  83.     add.w    #$2,a2            ; incr addr
  84.     move.l    a2,a0
  85.     rol.l    #$8,d2
  86.     move.l    d2,d0
  87.  
  88.     bsr.l    _dmem_write_byte        ; os  : write lo
  89.  
  90.     tst.l    d1            ; dfetch error?
  91.     bne.w    movp_write_err        ; yes
  92.  
  93.     add.w    #$2,a2            ; incr addr
  94.     move.l    a2,a0
  95.     rol.l    #$8,d2
  96.     move.l    d2,d0
  97.  
  98.     bsr.l    _dmem_write_byte        ; os  : write lo
  99.  
  100.     tst.l    d1            ; dfetch error?
  101.     bne.w    movp_write_err        ; yes
  102.  
  103.     add.w    #$2,a2            ; incr addr
  104.     move.l    a2,a0
  105.     rol.l    #$8,d2
  106.     move.l    d2,d0
  107.  
  108.     bsr.l    _dmem_write_byte        ; os  : write lo
  109.  
  110.     tst.l    d1            ; dfetch error?
  111.     bne.w    movp_write_err        ; yes
  112.  
  113.     bra    _movep_exit        ; (rts)
  114.  
  115. ; a0 = dst addr
  116. ; d0 = Dx
  117. r2mwtrans:
  118.     move.l    d0,d2            ; store data
  119.     move.l    a0,a2            ; store addr
  120.     lsr.w    #$8,d0
  121.  
  122.     bsr.l    _dmem_write_byte        ; os  : write hi
  123.  
  124.     tst.l    d1            ; dfetch error?
  125.     bne.w    movp_write_err        ; yes
  126.  
  127.     add.w    #$2,a2
  128.     move.l    a2,a0
  129.     move.l    d2,d0
  130.  
  131.     bsr.l    _dmem_write_byte        ; os  : write lo
  132.  
  133.     tst.l    d1            ; dfetch error?
  134.     bne.w    movp_write_err        ; yes
  135.  
  136.     bra    _movep_exit        ; (rts)
  137.  
  138. ; mem2reg: read bytes from memory.
  139. ; determines the dest register, and then writes the bytes into it.
  140. mem2reg:
  141.     btst    #$6,d1            ; word or long operation?
  142.     beq.b    m2rwtrans
  143.  
  144. ; a0 = dst addr
  145. m2rltrans:
  146.     move.l    a0,a2            ; store addr
  147.  
  148.     bsr.l    _dmem_read_byte        ; read first byte
  149.  
  150.     tst.l    d1            ; dfetch error?
  151.     bne.w    movp_read_err        ; yes
  152.  
  153.     move.l    d0,d2
  154.  
  155.     add.w    #$2,a2            ; incr addr by 2 bytes
  156.     move.l    a2,a0
  157.  
  158.     bsr.l    _dmem_read_byte        ; read second byte
  159.  
  160.     tst.l    d1            ; dfetch error?
  161.     bne.w    movp_read_err        ; yes
  162.  
  163.     lsl.w    #$8,d2
  164.     move.b    d0,d2            ; append bytes
  165.  
  166.     add.w    #$2,a2            ; incr addr by 2 bytes
  167.     move.l    a2,a0
  168.  
  169.     bsr.l    _dmem_read_byte        ; read second byte
  170.  
  171.     tst.l    d1            ; dfetch error?
  172.     bne.w    movp_read_err        ; yes
  173.  
  174.     lsl.l    #$8,d2
  175.     move.b    d0,d2            ; append bytes
  176.  
  177.     add.w    #$2,a2            ; incr addr by 2 bytes
  178.     move.l    a2,a0
  179.  
  180.     bsr.l    _dmem_read_byte        ; read second byte
  181.  
  182.     tst.l    d1            ; dfetch error?
  183.     bne.w    movp_read_err        ; yes
  184.  
  185.     lsl.l    #$8,d2
  186.     move.b    d0,d2            ; append bytes
  187.  
  188.     move.b    EXC_OPWORD(a6),d1
  189.     lsr.b    #$1,d1
  190.     and.w    #$7,d1            ; extract Dx from opcode word
  191.  
  192.     dc.w    $2F82,$1404        ; move.l   d2,(EXC_DREGS,a7,d1.w*4)   ; store dx
  193. ;    lsl.w    #2,d1
  194. ;    move.l    d2,EXC_DREGS(a7,d1.w)
  195. ;    lsr.w    #2,d1
  196.  
  197.     bra    _movep_exit        ; (rts)
  198.  
  199. ; a0 = dst addr
  200. m2rwtrans:
  201.     move.l    a0,a2            ; store addr
  202.  
  203.     bsr.l    _dmem_read_byte        ; read first byte
  204.  
  205.     tst.l    d1            ; dfetch error?
  206.     bne.w    movp_read_err        ; yes
  207.  
  208.     move.l    d0,d2
  209.  
  210.     add.w    #$2,a2            ; incr addr by 2 bytes
  211.     move.l    a2,a0
  212.  
  213.     bsr.l    _dmem_read_byte        ; read second byte
  214.  
  215.     tst.l    d1            ; dfetch error?
  216.     bne.w    movp_read_err        ; yes
  217.  
  218.     lsl.w    #$8,d2
  219.     move.b    d0,d2            ; append bytes
  220.  
  221.     move.b    EXC_OPWORD(a6),d1
  222.     lsr.b    #$1,d1
  223.     and.w    #$7,d1            ; extract Dx from opcode word
  224.  
  225.     dc.w    $3F82,$1406        ; move.w   d2,(EXC_DREGS+2,a7,d1.w*4) ; store dx
  226. ;    lsl.w    #2,d1
  227. ;    move.w    d2,EXC_DREGS+2(a7,d1.w)
  228. ;    lsr.w    #2,d1
  229.  
  230.     bra    _movep_exit        ; (rts)
  231.  
  232. ; if dmem_{read,write}_byte() returns a fail message in d1, the package
  233. ; must create an access error frame. here, we pass a skeleton fslw
  234. ; and the failing address to the routine that creates the new frame.
  235. ; FSLW:
  236. ;    write = true
  237. ;    size = byte
  238. ;    TM = data
  239. ;    software emulation error = true
  240. movp_write_err:
  241.     move.l    a2,a0            ; pass failing address
  242.     move.l    #$00a10001,d0        ; pass fslw
  243.     bra.l    _isp_dacc
  244.  
  245. ; FSLW:
  246. ;    read = true
  247. ;    size = byte
  248. ;    TM = data
  249. ;    software emulation error = true
  250. movp_read_err:
  251.     move.l    a2,a0            ; pass failing address
  252.     move.l    #$01210001,d0        ; pass fslw
  253.     bra.l    _isp_dacc
  254.  
  255. _dmem_read_byte:
  256.     movem.l    a1-a4,-(a7)
  257.  
  258.     move.l    a7,a4        ; save for later
  259.  
  260.     dc.w    $4E7A,$B801    ; movec      vbr,a3
  261. ;    sub.l    a3,a3
  262.  
  263.     move.l    $08(a3),a1    ; (bus err vector)
  264.     lea    _dmem_read_EXIT(pc),a2
  265.     move.l    a2,$08(a3)
  266.  
  267.     moveq    #-1,d1
  268.     move.b    (a0),d0        ; read byte
  269.     moveq    #0,d1
  270.  
  271. _dmem_read_EXIT:
  272.     move.l    a1,$08(a3)    ; (bus err vector)
  273.  
  274.     move.l    a4,a7        ; tidy up stack
  275.  
  276.     movem.l    (a7)+,a1-a4
  277.     rts
  278.  
  279. _dmem_write_byte:
  280.     movem.l    a1-a4,-(a7)
  281.  
  282.     move.l    a7,a4        ; save for later
  283.  
  284.     dc.w    $4E7A,$B801    ; movec      vbr,a3
  285. ;    sub.l    a3,a3
  286.  
  287.     move.l    $08(a3),a1    ; (bus err vector)
  288.     lea    _dmem_write_EXIT(pc),a2
  289.     move.l    a2,$08(a3)
  290.  
  291.     moveq    #-1,d1
  292.     move.b    d0,(a0)        ; write byte
  293.     moveq    #0,d1
  294.  
  295. _dmem_write_EXIT:
  296.     move.l    a1,$08(a3)    ; (bus err vector)
  297.  
  298.     move.l    a4,a7        ; tidy up stack
  299.  
  300.     movem.l    (a7)+,a1-a4
  301.     rts
  302.  
  303. _isp_dacc:            ; just ignore
  304.  
  305. _movep_exit:
  306.     addq.l    #4,EXC_PC(a7)
  307.     rts
  308.